package cc.lucien;

import java.lang.reflect.Field;

public class Demo04 {
    public static void main(String[] args) {
        // 获取 Student 类的 Class 对象
        Class clazz = Student.class;

        // 获取 public 修饰的域（属性）
        try {
            Field hobby = clazz.getField("hobby");
            System.out.println(hobby);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }

        Field[] fields = clazz.getFields();
        for (Field f : fields) {
            System.out.println(f);
        }

        // 获取声明的域（属性）
        fields = clazz.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            System.out.println(fields[i]);
        }
    }
}
